
#include <BShape>

#include "member_BShape.h"

using namespace BWE;

#define member					(*(member_BShape*)_ptr)
#define member_allocate()		_ptr = new member_BShape(this)
#define member_release()		delete (member_BShape*)_ptr

BShape::BShape()
{
	member_allocate();
}
BShape::~BShape()
{
	member_release();
}

void BShape::dirty()
{
	member.dirty = true;
}
void BShape::flush()
{
	if (member.dirty)
	{
		refresh();
		member.dirty = false;
	}
}

void BShape::setColor(const BColor& color)
{
	member.color = color;
}
void BShape::setColor(BByte r, BByte g, BByte b, BByte a)
{
	member.color.set(r, g, b, a);
}
const BColor& BShape::color() const
{
	return member.color;
}

void BShape::setMaterial(BMaterial* material)
{
	member.material = material;
}
BMaterial* BShape::material()
{
	return member.material.ptr();
}
const BMaterial* BShape::material() const
{
	return member.material.ptr();
}

void BShape::setTexture(BTexture* texture, int unit)
{
	if (unit > 20)
		return;
	if (member.textures.size() <= unit)
		member.textures.resize(unit + 1);
	member.textures.set(unit, texture);
}
BTexture* BShape::texture(int unit)
{
	return member.textures(unit);
}
const BTexture* BShape::texture(int unit) const
{
	return member.textures(unit);
}

void BShape::setProgram(BProgram* program)
{
	member.program = program;
}
BProgram* BShape::program()
{
	return member.program.ptr();
}
const BProgram* BShape::program() const
{
	return member.program.ptr();
}

void BShape::setSpace(const BSpace& space)
{
	if (member.space != space)
	{
		member.space = space;
		emit(Signal_SpaceChanged, member.space);
	}
}
const BSpace& BShape::space() const
{
	if (member.dirty)
		((BShape*)this)->flush();
	return member.space;
}
